package com.hjn.springboot.springbootthemeleaf.web;

import lombok.Data;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: huaijn
 * @create: 2022/5/2 14:08
 * @description: todo
 **/
@Controller
public class UserController {

    @RequestMapping("/userInfoDetail")
    public String userInfoDetail(Model model){
        model.addAttribute("message", "springboot继承themeleaf模板");
        return "userInfoDetail";
    }

    /**
     *@Author huaijn
     *@Date 2022/5/3 11:56
     *@Description 使用thymeleaf遍历userlist集合中的数据
     */
    @RequestMapping("/queryUserList")
    public String queryUserList(Model model){
        User user = null;
        List<User> userList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            user = new User();
            user.setAge(12+i);
            user.setName("zhangsan" + i);
            user.setUuid(100+i);
            userList.add(user);
        }
        model.addAttribute("userList", userList);
        return "queryUserList";
    }

    @Data
    private class User {
        private String name;
        private int uuid;
        private int age;
    }
}
